import { IResponse } from '@/types/data'
import { BannerItem, IGoodsNew, IGoodsHot } from '@/types/goods'
import request from '@/utils/request'
import { defineStore } from 'pinia'

export default defineStore('home', {
  state: () => ({
    list: [] as BannerItem[],
    newGoodsList: [] as IGoodsNew[],
    hotGoodsList: [] as IGoodsHot[],
  }),
  actions: {
    // 轮播图
    async getBannerList() {
      const r = await request.get<IResponse<BannerItem[]>>('/home/banner')
      this.list = r.data.result
    },
    // 新鲜好物
    async getNewGoodsList() {
      const r = await request.get<IResponse<IGoodsNew[]>>('/home/new')
      this.newGoodsList = r.data.result
    },
    // 人气推荐
    async getHotGoodsList() {
      const r = await request.get<IResponse<IGoodsHot[]>>('/home/hot')
      this.hotGoodsList = r.data.result
    },
  },
})
